'''
    pip install cx_Oracle
    导出oracle的所有表包含空表
'''

import os
import cx_Oracle

host = 'localhost'
port = '1521'
service_name = 'wbc'
user = 'zbdsj'
password = 'zbdsj'
dir = 'D:\\server\\databases\\oracle\\11.2.0\\backup\\zbdsj.dmp'
dsn = cx_Oracle.makedsn(host, port, service_name= service_name)
connection = cx_Oracle.connect(user=user, password=password, dsn=dsn)
cursor = connection.cursor()
cursor.execute("select 'alter table '||table_name||' allocate extent' from user_tables where num_rows=0")
rows = cursor.fetchall()
for row in rows:
    if row[0]:
        print(row[0])
        cursor.execute(row[0])
        connection.commit()
cursor.close()
connection.close()
cmd = 'exp userid={}/{}@{}:{}/{} file= {} log=export.log'.format(user,password,host,port,service_name,dir)
os.system(cmd)
